package com.ywy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywy.entity.Comment;
import com.ywy.mapper.CommentMapper;
import com.ywy.service.CommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 博客评论 服务实现类
 * </p>
 *
 * @author ywy
 * @since 2021-12-24
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public IPage listByPage(Page page, Integer postId, Integer userId, String order) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<Comment>()
                .eq(postId != null, "post_id", postId)
                .eq(userId != null, "user_id", userId)
                .orderByDesc(order != null, order);

        return commentMapper.listByPage(page, queryWrapper);
    }
}
